<?php

namespace App\Repositories;

use App\Models\System\Module;

/**
 * 系统模块Repository
 *
 * Date: 21/03/2018
 * @author George
 * @package App\Repositories\Module
 */
class ModuleRepository extends BaseRepository
{
	/**
	 * 定义模型类
	 *
	 * Date: 21/03/2018
	 * @author George
	 * @return mixed|string
	 */
	public function model()
	{
		return Module::class;
	}

	/**
	 * 获取免费的模块信息
	 *
	 * Date: 23/03/2018
	 * @author George
	 * @return $this
	 */
	public function getFreeModules()
	{
		return $this->where('pricing', '=', 0);
	}

	/**
	 * 获取子模块
	 *
	 * Date: 23/03/2018
	 * @author George
	 * @param $module
	 * @return mixed
	 * @throws \App\Exceptions\GeneralException
	 */
	public function getChildren($module)
	{
		if (!$module instanceof Module) {
			$module = $this->getByPrimary($module);
		}
		return $module->children()->get();
	}

	protected function serialization(array $attributes)
	{
		// TODO: Implement serialization() method.
	}
}
